<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 2017/1/8
 * Time: 1:07
 * File: function.array-search.php
 * Project: PHPTEST
 * Location: Wuxi
 */

//array_search — 在数组中搜索给定的值，如果成功则返回相应的键名

//mixed array_search ( mixed $needle , array $haystack [, bool $strict = false ] )

$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');

$key = array_search('green', $array); // $key = 2;
echo $key.PHP_EOL;
$key = array_search('red', $array);   // $key = 1;
echo $key.PHP_EOL;
